import index from './view/index.vue'
import mytask from './view/mytask.vue'
import mydone from './view/mydone.vue'
import assignable from './view/assignable.vue'
import running from './view/running.vue'
import pausing from './view/pausing.vue'
import finished from './view/finished.vue'

var _routes = []
var routesCache = {}
var _menus = [{
    name: 'index',
    path: '/',
    component: index,
    meta: {
      title: '首页'
    }
  },
  {
    name: 'assignable',
    path: '/assignable',
    component: assignable,
    meta: {
      title: '未分配任务'
    }
  },
  {
    name: 'mytask',
    path: '/mytask',
    component: mytask,
    meta: {
      title: '我的待办'
    }
  },
  {
    name: 'mydone',
    path: '/mydone',
    component: mydone,
    meta: {
      title: '我的已办'
    }
  },
  {
    name: 'manage',
    path: '/',
    meta: {
      title: '流程管理'
    },
    children: [{
        name: 'running',
        path: '/running',
        component: running,
        meta: {
          title: '活动流程'
        }
      },
      {
        name: 'pausing',
        path: '/pausing',
        component: pausing,
        meta: {
          title: '暂挂流程'
        }
      },
      {
        name: 'finished',
        path: '/finished',
        component: finished,
        meta: {
          title: '完结流程'
        }
      }
    ]
  }
]

function buildRoute(array) {
  array.forEach(item => {
    if (item.component) {
      if (!routesCache[item.name]) {
        routesCache[item.name] = item
        _routes.push(item)
      }
    } else if (item.children) {
      buildRoute(item.children)
    }
  })
}
buildRoute(_menus)

export const routes = _routes
export const menus = _menus
